package com.jxsd.edu.cn.struts2.daoImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.SearchPubMsgDao;
import com.jxsd.edu.cn.struts2.models.PubMsgview;
import com.jxsd.edu.cn.tools.Page;
import com.jxsd.edu.cn.tools.PageBean;
import com.jxsd.edu.cn.tools.Participle;
import com.jxsd.edu.cn.tools.ResultList;

public class SearchPubMsgDaoImpl implements SearchPubMsgDao {

	@Override
	public Page<PubMsgview> doDearch(PageBean<PubMsgview>  pagebean,String keyword) 
	{
		String  sql="  select  publishID,title,postTime,cover,smallId,smallName,cityName,univerName  " +
				    "  from  pubmsgview  where   ";
		String  sql1="  order  by  postTime  ";
		
		if(keyword.length()>1)
		{
			List<String>  list=Participle.getStrings(keyword);//获取分词
			if(null!=list&&list.size()>=1)
			{
				String  sql2=Participle.getFenCiSql(list, "title");
				sql+=sql2;
				sql+=sql1;
			}
			else
			{
				sql+=" title  like  '%*%' ";
			}
			
		}
		else
		{
			sql+=" title  like'%";
			sql+=keyword;
			sql+="%'";
			sql+=sql1;
		}
		
		ResultList<PubMsgview>   hander=new  ResultList<PubMsgview>();
		Page<PubMsgview>  page=null;
		try {
			page=hander.pageHandlerState(pagebean, sql, PubMsgview.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return page;
	}
}
